﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using YLServerInterface.YLAdminService;

namespace YLServerInterface.NavigateWindows
{
    enum DataType
    {
        WatingProcess,
        Finish,
        Uploading,
        Downloaded,
        Processing
    }
    static class DataTypeExtension
    {
        public static DataType FromString(this string t)
        {
            switch (t)
            {
                case "待制作":
                    return DataType.WatingProcess;
                case "正在上传":
                    return DataType.Uploading;
                case "已完成":
                    return DataType.Finish;
                case "下载完成":
                    return DataType.Downloaded;
                case "正在制作":
                    return DataType.Processing;
            }
            throw new Exception("不存在该类型");
        }
        public static string ToString(this DataType t)
        {
            switch (t)
            {
                case DataType.WatingProcess:
                    return "待制作";
                case DataType.Finish:
                    return "已完成";
                case DataType.Uploading:
                    return "正在上传";
                case DataType.Downloaded:
                    return "下载完成";
                case DataType.Processing:
                    return "正在制作";
            }
            throw new Exception("不存在该类型");
        }
    }
    /// <summary>
    /// Interaction logic for UserItemsPage.xaml
    /// </summary>
    public partial class UserItemsPage : Page
    {

        public UserItemsPage()
        {
            InitializeComponent();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var items = DataContext as WorkItem[];
            WorkItem[] newItems = null;
            switch ((cmbShowDataType.SelectedValue as ComboBoxItem).Content.ToString().FromString())
            {
                case DataType.WatingProcess:
                    newItems = items.Where(item =>
                        item.Status.FromString() == DataType.WatingProcess)
                        .ToArray();
                    break;
                case DataType.Finish:
                    newItems = items.Where(item =>
                        item.Status.FromString() == DataType.Finish)
                        .ToArray();
                    break;
                case DataType.Uploading:
                    newItems = items.Where(item =>
                        item.Status.FromString() == DataType.Uploading)
                        .ToArray();
                    break;
            }
            lstItems.DataContext = newItems;
        }
        private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)
        {
            frmImageOp imgOp = new frmImageOp();
            imgOp.DataContext = (e.OriginalSource as Button).DataContext;
            NavigationService.Navigate(imgOp);
        }
    }
}
